package com.aloda.ojjudge.codesandbox;

import com.aloda.ojjudge.pojo.enums.CodeSandboxEnum;
import com.aloda.ojjudge.codesandbox.impl.ExampleCodeSandbox;
import com.aloda.ojjudge.codesandbox.impl.RemoteCodeSandbox;
import com.aloda.ojjudge.codesandbox.impl.ThirdPartyCodeSandbox;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CodeSandboxFactory {

    private static ExampleCodeSandbox exampleCodeSandbox;
    private static RemoteCodeSandbox remoteCodeSandbox;
    private static ThirdPartyCodeSandbox thirdPartyCodeSandbox;

    @Autowired
    public CodeSandboxFactory(ExampleCodeSandbox exampleCodeSandbox,
                              RemoteCodeSandbox remoteCodeSandbox,
                              ThirdPartyCodeSandbox thirdPartyCodeSandbox) {
        CodeSandboxFactory.exampleCodeSandbox = exampleCodeSandbox;
        CodeSandboxFactory.remoteCodeSandbox = remoteCodeSandbox;
        CodeSandboxFactory.thirdPartyCodeSandbox = thirdPartyCodeSandbox;
    }

    /**
     * 创建代码沙箱示例
     *
     * @param codeSandboxEnum 沙箱类型
     * @return
     */
    public static CodeSandbox newInstance(CodeSandboxEnum codeSandboxEnum) {
        switch (codeSandboxEnum) {
            case EXAMPLE:
                return exampleCodeSandbox;
            case REMOTE:
                return remoteCodeSandbox;
            case THIRD_PARTY:
                return thirdPartyCodeSandbox;
            default:
                return exampleCodeSandbox;
        }
    }
}